require_relative '../lib/maze'

module MazeHelper
  ORTHOGONAL = :orthogonal
  SIGMA      = :sigma

  def self.output(type, format, output_file = nil)
    width  = (ARGV[0] || 10).to_i
    height = (ARGV[1] || width).to_i
    seed   = (ARGV[2] || rand(0xFFFF_FFFF)).to_i

    srand(seed)

    params = { :width => width, :height => height }
    maze = Maze.const_get(type.capitalize).new(params)

    puts maze.generate.draw(:text)
    unless :text == format
      maze.generate.draw(:png, output_file)
    end

    puts "Generated with: #{__FILE__} #{width} #{height} #{seed}"
    puts "Written to output file: #{output_file}" if output_file
  end

  def self.draw(type, format = :text, output_file = nil)
    begin
      output(type, format, "output_#{type}.png")
    rescue SystemStackError
      puts "Sorry but the dimensions you provided are too big. " +
           "Please try something smaller! (Recommended: 70x70) " +
           "Try an even lower dimension if the recommended "     +
           "dimensions reproduces this same error."
    end
  end
end


